$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'exam/examination/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true , hidden:true},
			{ label: '试卷id', name: 'paperId', index: 'paper_id', width: 80 , hidden:true},	
			{ label: '考试专业id', name: 'majorId', index: 'major_id', width: 80, hidden:true},
			{ label: '考试部门id', name: 'examinationDeptId', index: 'examination_dept_id', width: 80, hidden:true},
			{ label: '考试名字', name: 'examinationName', index: 'examination_name', width: 80 }, 			
			{ label: '考试部门', name: 'deptName', index: 'deptName', width: 80 }, 			
			/*{ label: '考试专业', name: 'majorName', index: 'majorName', width: 80 },*/ 			
			{ label: '考试开始时间', name: 'examinationStartTime', index: 'examination_start_time', width: 80 }, 			
			{ label: '考试结束时间', name: 'examinationEndTime', index: 'examination_end_time', width: 80 }, 			
			{ label: '可考次数', name: 'examinationNumber', index: 'examination_number', width: 80 }, 		
			{ label: '过关分数', name: 'examinationPassScore', index: 'examination_pass_score', width: 80 },
			/*{ label: '考试时长', name: 'examinationTimeLong', index: 'examination_time_long', width: 80 }, 			
			{ label: '考试注意事项', name: 'examinationAttention', index: 'examination_attention', width: 80 }, 			
			{ label: '二维码内容', name: 'qrCode', index: 'qr_code', width: 80 },*/ 			
			{ label: '考试状态', name: 'examinationState', index: 'examination_state', width: 80 , formatter: function(value, options, row){
				return value === 1 ? 
						'<span class="label label-danger" value="1">已发布</span>' : 
						'<span class="label label-success" value="0">未发布</span>';
			}}, 
			{ label: '考试状态', name: 'examinationState', index: 'examination_state', width: 80 , hidden:true}, 
			{ label: '创建时间', name: 'createTime', index: 'create_time', width: 90 , formatter:function(value,options,row){
                return new Date(value).Format('yyyy-MM-dd HH:mm:ss');}},			
			/*{ label: '修改时间', name: 'updateTime', index: 'update_time', width: 80 },*/ 			
			 			
			{ label: '创建部门id', name: 'deptId', index: 'dept_id', width: 80 , hidden:true},			
			{ label: '状态', name: 'disFlag', index: 'dis_flag', width: 80 , hidden:true, formatter: function(value, options, row){
				return value === 1 ? 
						'<span class="label label-danger" value="1">禁用</span>' : 
						'<span class="label label-success" value="0">启用</span>';
			}},
			{ label: '创建人', name: 'createName', index: 'createName', width: 80 }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        multiboxonly:true, // 单选.
        beforeSelectRow: beforeSelectRow, // 单选控制.
        pager: "#jqGridPager",
        jsonReader : {
            root: "examination.list",
            page: "examination.pageNum",
            total: "examination.pages",
            records: "examination.total"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	// 隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        	// 隐藏全选.
        	$("#jqgh_jqGrid_cb").hide();
        }
    });
    // 单选控制.
    function beforeSelectRow() {
        $("#jqGrid").jqGrid('resetSelection');
        $("#jqgh_jqGrid_cb").hide(); 
        return(true);
    }

    
    $('.summernote').summernote({
		height : '220px',
		lang : 'zh-CN',
		callbacks: {
            onImageUpload: function(files, editor, $editable) {
                sendFile(files);
            }
        }
	});
    
    
    // 试卷查看列表.
    $("#paperJqGrid").jqGrid({
        url: baseURL + '/exam/paperProduce/getPaperList',
        datatype: "json",
        colModel: [         
            { label: '<div>试卷名称</div>', name: 'paperName', index: 'name', width: 80 },
            {
                label: '操作', name: 'flag', index: 'flag', width: 80, align: 'center',
                formatter: function (cellvalue, options, rowObject) {
                    var html = 
                            "<a class='btn btn-primary' onclick='seePaper(" + rowObject.id +", \"" + rowObject.paperName + "\")'/ value='查看'><span class='glyphicon glyphicon-book'></span>&nbsp;查看</a>"
                        + "  <a class='btn btn-primary' onclick='downLoadPaper(" + rowObject.id +", \"" + rowObject.paperName + "\")'/ value='下载pdf'><span class='glyphicon glyphicon-download-alt'></span>&nbsp;下载pdf</a>";
                    return html;
                },
            }
        ],
        viewrecords: true,
        width: 500,
        height: 500,
        jsonReader : {
            root: "paperList"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#paperJqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
    // 试卷查看列表.
    $("#studentJqGrid").jqGrid({
        url: baseURL + '/exam/examinationStudent/list',
        datatype: "json",
        colModel: [
            { label: '<div>部门名称</div>', name: 'deptName', index: 'dept_name', width: 80 },
            { label: '<div>登录账户</div>', name: 'userName', index: 'user_name', width: 80 },
            { label: '<div>学生姓名</div>', name: 'studentName', index: 'name', width: 80 },
            { label: '<div>准考证号</div>', name: 'registrationNum', index: 'registration_num', width: 100 },
            /*{
                label: '操作', name: 'flag', index: 'flag', width: 80, align: 'center',
                formatter: function (cellvalue, options, rowObject) {
                    var html =
                            "<a class='btn btn-primary' onclick='seePaper(" + rowObject.id +", \"" + rowObject.paperName + "\")'/ value='查看'><span class='glyphicon glyphicon-book'></span>&nbsp;查看</a>"
                        + "  <a class='btn btn-primary' onclick='downLoadPaper(" + rowObject.id +", \"" + rowObject.paperName + "\")'/ value='下载pdf'><span class='glyphicon glyphicon-download-alt'></span>&nbsp;下载pdf</a>";
                    return html;
                },
            }*/
        ],
        viewrecords: true,
		rowNum: 10,
		height: 500,
		rowList : [10,30,50],
		multiselect: true,
		multiboxonly:true, // 单选.
		pager:"#studentJqGrid",
        jsonReader : {
			root: "page.list",
			page: "page.pageNum",
			total: "page.pages",
			records: "page.total",
        },
		prmNames : {
			page:"page",
			rows:"limit",
			order: "order"
		},
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#studentJqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
	vm.getDept();
});

var setting = {
	  data: {
	      simpleData: {
	         enable: true,
	         idKey: "deptId",
	         pIdKey: "parentId",
	         rootPId: -1
	        },
	      key: {
	         url:"nourl"
	      }
	  }
};
var setting = {
	data: {
		simpleData: {
			enable: true,
			idKey: "deptId",
			pIdKey: "parentId",
			rootPId: -1
		},
		key: {
			url:"nourl"
		}
	}
};
var ztree;

var vm = new Vue({
	el:'#rrapp',
	data:{
		majorLists:{},
		paperList:{},
		studentList:{},
		showList: true,
		showStudent:true,
		title: null,
        highestPassScore: 0, // 最高过关分数，选择试卷的总分数.
        examination: {deptName:null, examinationDeptId:null},
		userName:null,//学生名称
		deptId:null,
		deptName:null,
		deptNo:null,
		photoTimeList:[
					{id: '0',name: '0次'},
					{id: '1',name: '1次'},
					{id: '2',name: '2次'},
					{id: '3',name: '3次'}
		],
		hideCountSumList:[
							{id: '0',name: '0次'},
							{id: '1',name: '1次'},
							{id: '2',name: '2次'},
							{id: '3',name: '3次'},
							{id: '4',name: '4次'},
							{id: '5',name: '5次'},
							{id: '6',name: '6次'},
							{id: '7',name: '7次'},
		],
		
	},

	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.examination = {deptName:null, examinationDeptId:null};
			vm.getMajorList();
			vm.getDept();
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			
			//使用公用方法获取选中的数据.
			var rowData =getRowData(id);
			var state=rowData.examinationState;
			if(state!=0){
				layer.msg("试卷已发布，不允许修改");
				return ;
			}
			
			vm.showList = false;
            vm.title = "修改";
            vm.getInfo(id);
            vm.getMajorList();
            
            vm.getDept();
		},
		getDept: function(){
			//加载部门树
			$.get(baseURL + "sys/dept/list", function(r){
				ztree = $.fn.zTree.init($("#deptTree"), setting, r);
				var node = ztree.getNodeByParam("deptId", vm.examination.examinationDeptId);
				if(node != null){
					ztree.selectNode(node);
					//修改时，不能回显.下边的解决了.
					//vm.workDaily.deptName = node.name;
					Vue.set(vm, 'deptName', node.name)
					Vue.set(vm.examination, 'deptName', node.name)
				}
			})
		},
		deptTree: function(){
	        layer.open({
	            type: 1,
	            offset: '50px',
	            skin: 'layui-layer-molv',
	            title: "选择部门",
	            area: ['300px', '450px'],
	            shade: 0,
	            shadeClose: false,
	            content: jQuery("#deptLayer"),
	            btn: ['确定', '取消'],
	            btn1: function (index) {
	                var node = ztree.getSelectedNodes();
	                //选择上级部门
	                vm.deptId = node[0].deptId;
	                vm.deptName = node[0].name;
					vm.deptNo = node[0].deptNo;
					vm.examination.examinationDeptId = node[0].deptId;
					vm.examination.deptName = node[0].name;
	                layer.close(index);
	            }
	        });
	    },
        // 重载获取试卷列表.
        reloadPaperList: function (paperDesignId) {
            var page = $("#paperJqGrid").jqGrid('getGridParam','page');
            $("#paperJqGrid").jqGrid('setGridParam',{
                postData:{'paperDesignId': paperDesignId},
                page:page
            }).trigger("reloadGrid");
        },
        // 获取试卷列表.
        getPaperDList : function () {
            var id = getSelectedRow();
            if(id == null){
                return;
            }
            
            console.log(getRowData(id));
            vm.reloadPaperList(getRowData(id).paperId);
            
            layer.open({
                type: 1,
                offset: '50px',
                skin: 'layui-layer-molv',
                title: "试卷列表",
                area: ['500px', '500px'],
                shade: 0,
                shadeClose: false,
                content: jQuery("#paperList"),
                btn: ['取消']
            });
        },
		resetStudent(){
			vm.deptNo=''
			vm.deptId=''
			vm.deptName=''
			vm.userName=''
		},
		searchStudent(){
			var id = getSelectedRow();
			this.reloadStudentList(id);
		},
        reloadStudentList: function (id) {
			if (id==undefined){
				id = getSelectedRow();
			}
            var page = $("#studentJqGrid").jqGrid('getGridParam','page');
            var rowNum = $("#studentJqGrid").jqGrid('getGridParam','rowNum');
            $("#studentJqGrid").jqGrid('setGridParam',{
               //postData:{examId: id,userName: userName1,deptNo: deptNo1},
				postData:{
					'examId': id,
						'userName': vm.userName,
						'deptNo': vm.deptNo
				},
                page:page,
				limit:rowNum
            }).trigger("reloadGrid");
        },
        // 获取学生列表.
        getStudentList : function () {
            var id = getSelectedRow();
            if(id == null){
                return;
            }

            console.log(getRowData(id));

            vm.deptNo=''
			vm.deptName=''
			vm.userName=''

			var deptNo=vm.deptNo;
			var userName=vm.userName;
            vm.reloadStudentList(getRowData(id).id);
			vm.showStudent=false;
        },
		exportStudentList:function(){
			var id = getSelectedRow();
			if(id == null){
				return;
			}
			if(vm.deptNo==null){
				vm.deptNo=''
			}
			if(vm.userName==null){
				vm.userName=''
			}

			var url = "/sage/exam/score/imp?deptNo="+vm.deptNo
				+"&userName="+vm.userName;
			var url = "exam/examinationStudent/export?examId="+getRowData(id).id+"&deptNo="+vm.deptNo
				+"&userName="+vm.userName;

			window.location.href = baseURL +url;
		},
		//模板下载
		downLoadStudent(){
			var url = "exam/examinationStudent/download";
			window.location.href = baseURL +url;
		},
		//自动生成
		autoByDeptId(){
			var id = getSelectedRow();
			layer.open({
				type: 1,
				offset: '50px',
				skin: 'layui-layer-molv',
				title: "结果",
				shade: 0,
				shadeClose: false,
				content: "是否按照考试范围自动生成所有的考生信息？",
				btn: ['确定', '取消'],
				btn1: function (index) {
					var formData = new FormData();
					formData.append('examId', id);
					$.ajax({
						url: baseURL + "exam/examinationStudent/autoByDeptId",
						type: 'POST',
						cache: false,
						data: formData,
						processData: false,
						contentType: false,
						success: function (r) {
							if(vm.deptNo==null){
								vm.deptNo=''
							}
							if(vm.userName==null){
								vm.userName=''
							}
							var deptNo=vm.deptNo;
							var userName=vm.userName;
							vm.reloadStudentList(id);
							parent.layer.open({
								type: 1,
								skin: 'layui-layer-molv',
								title: "结果",
								shade: 0,
								shadeClose: false,
								content: "自动生成"+r.count+"条数据",
								btn: ['确定','取消'],
								btn1:function (index) {
									parent.parent.layer.closeAll();
									parent.layer.closeAll();
								}
							})

						},
						error: function (err) {
						}

					});
					layer.close(index);
				}
			})
		},
		imp(){
			var id = getSelectedRow();
			layer.open({
				type: 1,
				offset: '50px',
				skin: 'layui-layer-molv',
				title: "导入",
				area: ['500px', '500px'],
				shade: 0,
				shadeClose: false,
				content: jQuery("#impList"),
				btn: ['确定','取消'],
				btn1:function (index) {
					var formData = new FormData();
					formData.append('file', $('#file')[0].files[0]);
					formData.append('examId', id);
					$.ajax({
						url: baseURL + "exam/examinationStudent/imports",
						type: 'POST',
						cache: false,
						data: formData,
						processData: false,
						contentType: false,
						success: function (r) {
							console.log(r);
							var list = r.oldStudentList;
							var count=r.count;
							var al="错误数据:</br>";
							if(list.length>0){
								for(var i=0; i<list.length;i++){
									var userName = list[i].userName;
									var deptName = list[i].deptName;
									var studentName = list[i].studentName;

									al +="部门名称: " + deptName +" ， 用户名："+ userName +" ， 登录名:" + studentName+'</br>';
								}
							}
							al+="成功导入:"+r.count+"条数据,已存在："+r.old+"条数据";
							if(vm.deptNo==null){
								vm.deptNo=''
							}
							if(vm.userName==null){
								vm.userName=''
							}
							var deptNo=vm.deptNo;
							var userName=vm.userName;
							vm.reloadStudentList(id);
							parent.layer.open({
								type: 1,
								offset: '50px',
								skin: 'layui-layer-molv',
								title: "结果",
								area: ['500px', '500px'],
								shade: 0,
								shadeClose: false,
								content: al,
								btn: ['确定','取消'],
								btn1:function () {
									parent.parent.layer.closeAll();
									parent.layer.closeAll();
								}
							})

						},
						error: function (err) {
						}

					});
					layer.close(index);
				}
			});
		},
		saveOrUpdate: function (event) {
			var url = vm.examination.id == null ? "exam/examination/save" : "exam/examination/update";
			vm.examination.examinationStartTime= $("#examinationStartTime").val();
			vm.examination.examinationEndTime= $("#examinationEndTime").val();
			vm.examination.examinationAttention = $("#examinationAttention").summernote('code');
			
            //  校验参数.
            if(!this.checkParam()) {
                return false;
            }
            
//            if(vm.examination.photoTimes>3 || vm.examination.hideCountSum<3){
//            	layer.open({
//    				type: 1,
//    				offset: '50px',
//    				skin: 'layui-layer-molv',
//    				title: "提示",
//    				area: ['500px', '500px'],
//    				shade: 0,
//    				shadeClose: false,
//    				content: "拍照次数不能大于3次,切屏次数不能小于3次",
//    				btn: ['确定','取消'],
//    				btn1:function (index) {
//    					
//    				}
//    			});
//            	
//            	return false;
//            }

			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.examination),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			//使用公用方法获取选中的数据.
			var rowData =getRowData(ids);
			var state=rowData.examinationState;
			if(state!=0){
				layer.msg("试卷已发布，不允许删除!!!");
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "exam/examination/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "exam/examination/info/"+id, function(r){
                vm.examination = r.examination;
                
                debugger
                //给富文本编辑器赋值.
    			$('#examinationAttention').summernote('code', vm.examination.examinationAttention);
            });
		},
		generateRq: function(event){
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			
			//使用公用方法获取选中的数据.
			var rowData =getRowData(id);
			var state=rowData.examinationState;
			
			vm.examination.id=id;
			
			if(state!=0){
				confirm('确定要取消发布考试选中的记录？', function(){
					$.ajax({
						type: "POST",
					    url: baseURL + "exam/examination/cancel",
	                    contentType: "application/json",
	                    data: JSON.stringify(vm.examination),
					    success: function(r){
							if(r.code == 0){
								alert('操作成功', function(index){
									$("#jqGrid").trigger("reloadGrid");
								});
							}else{
								alert(r.msg);
							}
						}
					});
				});
			}else{
				
				confirm('确定要发布考试选中的记录？', function(){
					$.ajax({
						type: "POST",
						url: baseURL + "exam/examination/generateRq/",
						contentType: "application/json",
						data: JSON.stringify(id),
						success: function(r){
							if(r.code == 0){
								alert('操作成功', function(index){
									$("#jqGrid").trigger("reloadGrid");
								});
							}else{
								alert(r.msg);
							}
						}
					});
				});
			}
			
		},
		seeRq: function(event){
			var id = getSelectedRows();
			//使用公用方法获取选中的数据.
			var rowData =getRowData(id);
			var state=rowData.examinationState;
			if(id == null){
				return ;
			}
			if(state!=1){
				layer.msg("试卷没有发布");
				return ;
			}
			$.get(baseURL + "exam/examination/find/"+id, function(r){
				if (r.code==0) {
					var data = r.data;
					if(data != null &&data != '') {
						var qrcode = data.qrCode;
						layer.open({
							title : '考试名称：'+data.examinationName,
							type: 1,
							skin: 'layui-layer-rim', //加上边框
							area: ['400px', '400px'], //宽高
							content: '<div><img src="data:image/jpg;base64,'+qrcode+'" /></div>'
						});
						
					}
				}else{
					layer.msg(r.msg);
				}
			});
		},
		reload: function (event) {
			vm.showList = true;
			vm.showStudent=true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		},
		//获取专业列表.
		getMajorList: function (event) {
			$.get(baseURL + "exam/major/getList", function(r){
				vm.majorLists = r.majorList;
            });
		},
		//根据专业获取已发布试卷.
		getPaperList: function (majorId) {
			/*var majorId="001";*/
			var data = {majorId:majorId};
			$.get(baseURL + "exam/paperDesign/getList",data, function(r){
				vm.paperList = r.data;
            });
		},
        // 根据试卷，获取试卷id.
        setHighestPassScore: function (paperId) {
            var paperList = vm.paperList;
            if (paperList == null || paperList == undefined || paperList.length == 0 ) {
                vm.highestPassScore = 0;
            }
            for (var i =0 ;i < paperList.length; i++ ) {
                var paperObj = paperList[i];
                if (paperObj == null || paperObj == undefined) {
                    vm.highestPassScore = 0;
                }
                if (paperObj != null && paperObj != undefined && paperObj.id == paperId) {
                    vm.highestPassScore = paperObj.totalScore;
                }
            }
        },
        // ===================校验参数=========================== 校验参数 ===============================校验参数==================
        checkParam: function() {
            if (vm.examination.examinationDeptId == undefined || vm.examination.examinationDeptId == null) {
                tips('请选择所属部门！', 'examinationDeptId');
                scrollto("#examinationDeptId");
                return false;
            } else if (vm.examination.majorId == undefined || vm.examination.majorId == null) {
                tips('请选择专业名称！', 'majorId');
                scrollto("#majorId");
                return false;
            } else if (vm.examination.paperId == undefined || vm.examination.paperId == null) {
                tips('请选择试卷！', 'paperId');
                scrollto("#paperId");
                return false;
            } else if (vm.examination.examinationName == undefined || vm.examination.examinationName == null || vm.examination.examinationName == "") {
                tips('请输入考试名字！', 'examinationName');
                scrollto("#examinationName");
                return false;
            } else if (vm.examination.examinationStartTime == undefined || vm.examination.examinationStartTime == null || vm.examination.examinationStartTime == "") {
                tips('请选择考试开始时间！', 'examinationStartTime');
                scrollto("#examinationStartTime");
                return false;
            } else if (vm.examination.examinationEndTime == undefined || vm.examination.examinationEndTime == null || vm.examination.examinationEndTime == "") {
                tips('请选择考试结束时间！', 'examinationEndTime');
                scrollto("#examinationEndTime");
                return false;
            } else if (vm.examination.examinationNumber == undefined || vm.examination.examinationNumber == null
                || vm.examination.examinationNumber == "" || vm.examination.examinationNumber < 0) {
                tips('请输入可考次数！', 'examinationNumber');
                scrollto("#examinationName");
                return false;
            } else if (!/^\+?[1-9][0-9]*$/.test(vm.examination.examinationNumber) || vm.examination.examinationNumber.length < 1 || vm.examination.examinationNumber.length > 8) {
                tips('可考次数为1~8位数字！', 'examinationNumber');
                scrollto("#examinationName");
                return false;
            } else if (vm.examination.examinationPassScore == undefined || vm.examination.examinationPassScore == null
                || vm.examination.examinationPassScore == "" || vm.examination.examinationPassScore < 0) {
                tips('请输入过关分数！', 'examinationPassScore');
                scrollto("#examinationPassScore");
                return false;
            }  else if (!/^\+?[1-9][0-9]*$/.test(vm.examination.examinationPassScore) || vm.examination.examinationPassScore.length < 1 || vm.examination.examinationPassScore.length > 4) {
                tips("过关分数为1~4位数字，试卷的最高分数为："+ vm.highestPassScore + "， 过关分数不能高于此分数！", 'examinationPassScore');
                scrollto("#examinationPassScore");
                return false;
            } else if (parseInt(vm.examination.examinationPassScore, 10) > parseInt(vm.highestPassScore, 10)) {
                tips("试卷的最高分数为："+ vm.highestPassScore + "， 过关分数不能高于此分数！", 'examinationPassScore');
                scrollto("#examinationPassScore");
                return false;
            } else if (vm.examination.examinationTimeLong == undefined || vm.examination.examinationTimeLong == null
                || vm.examination.examinationTimeLong == "" || vm.examination.examinationTimeLong < 0) {
                tips('请输入考试时长！', 'examinationTimeLong');
                scrollto("#examinationTimeLong");
                return false;
            }  else if (!/^\+?[1-9][0-9]*$/.test(vm.examination.examinationTimeLong) || vm.examination.examinationTimeLong.length < 1 || vm.examination.examinationTimeLong.length > 4) {
                tips('考试时长为1~4位数字！', 'examinationTimeLong');
                scrollto("#examinationTimeLong");
                return false;
            }else if (!/^\+?[0-9]*$/.test(vm.examination.photoTimes) || vm.examination.photoTimes>3) {
                tips('考试拍照次数不能超过3次！', 'photoTimes');
                scrollto("#photoTimes");
                return false;
            }else if (!/^\+?[1-9][0-9]*$/.test(vm.examination.hideCountSum) || vm.examination.hideCountSum<3) {
                tips('可切屏次数不能少于3次！', 'hideCountSum');
                scrollto("#hideCountSum");
                return false;
            }
            return true;
        }
	},
	mounted: function(){
        laydate.render({
           elem: '#examinationStartTime', //指定元素
           type: 'datetime',
           istime: true,
           choose: function(dates){ // 选择日期完毕的回调
        	   vm.examination.examinationStartTime=dates;
           }
       });
        laydate.render({
            elem: '#examinationEndTime', //指定元素
            istime: true,
            type: 'datetime'
        });
   }
});

// 下载pdf.
function downLoadPaper(id, paperName) {
    location.href= baseURL +"exam/paperProduce/download?produceId=" + id + "&paperName=" + paperName;
}

// 查看试卷.
function seePaper (paperId, paperName) {
    $.ajax({
        type : 'post',
        data : {produceId : paperId},
        url : "/exam/paperProduce/getQuestionInfo",
        success : function(r) {
            var paperInfoHtml = '<ul>';
            // 循环题目.
            $.each(r.questionList, function(i,y) {
                paperInfoHtml += i + 1 + ". [" + y.typeName + "] " + y.content + "(" + y.score + "分)" + "<br/>";
                
                // 循环选项.
                $.each(y.optionList, function(j,z) {
                    paperInfoHtml += z.flag + "." + z.content+ "<br/>";
                })
                paperInfoHtml += "<br/>";
                
            })
            paperInfoHtml += '<br/><br/><br/><br/><br/>';
            paperInfoHtml +=  '答案<br/>' + r.answer;
            paperInfoHtml += '</ul>';
          $("#paperInfo").html(paperInfoHtml);
          
          
          layer.open({
              type: 1,
              offset: '50px',
              skin: 'layui-layer-molv',
              title: "试卷查看--" + paperName,
              area: ['700px', '700px'],
              shade: 0,
              shadeClose: false,
              content: jQuery("#paperInfo"),
              btn: ['取消']
          });
        }
    });
}